Analog Clock
TI-84 and upper calculators have built-in ways to keep track of time. However, all these functions display time digitally. This code will allow the calculator to display the time with an analog 12-hour clock. Needed Commands getTime is essential for this code, although several other common commands are used as well. Code TI-84 :prgmANLCLOCK :"A CLOCK : :prgmCLRGRAPH :Xmax/2 Xmax :Ymax/2 Ymax :-Xmax Xmin :-Ymax Ymin :Degree : :15 H:20 M:18 S : :Circle(0,0,30) :For(X,1,12) ::Text(28-int(cos(X*30)*25),46+int(sin(30*X)*25),X) :End : :{0,0,0} ANG : :While getKey=0 ::getTime TIME :: ::If TIME(3)≠ ANG(3)/6:[[Line(]]0,0,sin( ANG(3))*S,cos( ANG(3))*S,0) :: ::If TIME(2)≠ ANG(2)/6:Then :::Line(0,0,sin( ANG(2))*M,cos( ANG(2))*M,0) :::Line(0,0,sin( ANG(1))*H,cos( ANG(1))*H,0) ::End :: ::"SET ANGS :: TIME(1)*30+ TIME(2)/2 ANG(1) :: TIME(2)*6 ANG(2) :: TIME(3)*6 ANG(3) :: ::Line(0,0,sin( ANG(1))*H,cos( ANG(1))*H ::Line(0,0,sin( ANG(2))*M,cos( ANG(2))*M ::Line(0,0,sin( ANG(3))*S,cos( ANG(3))*S :: :End TI-89 :anlclock() :Prgm :ClockOn : :setMode("Angle","RADIAN") : :78 [[xmax]]:-xmax xmin :38 [[ymax]]:-ymax ymin :ClrGraph :Circle 0,0,36 :For ,1,12 ::PtText string( ),30*[[sin(]] * /6)-3,30*[[cos(]] * /6)+2 :EndFor : :15 hlen:20 mlen:18 slen :{0,0,0} angs:{0,0,0} time : :While getKey()=0 :: ::If getTime()3 time3 Then :::Line 0,0,slen*sin(angs3),slen*cos(angs3),0 ::: :::If getTime()2 time2 Then ::::Line 0,0,mlen*sin(angs2),mlen*cos(angs2),0 ::::Line 0,0,hlen*sin(angs1),hlen*cos(angs1),0 :::EndIf ::: :::getTime() time ::: :::time1* /6 angs1 :::time2* /30 angs2 :::time3* /30 angs3 ::: :::Line 0,0,hlen*sin(angs1),hlen*cos(angs1),1 :::Line 0,0,mlen*sin(angs2),mlen*cos(angs2),1 :::Line 0,0,slen*sin(angs3),slen*cos(angs3),1 ::: ::EndIf :EndWhile : :DelVar hlen,mlen,slen,angs,time : :EndPrgm Code Analysis :prgmCLRGRAPH :Xmax/2 XMax :Ymax/2 YMax :-XMax Xmin :-Ymax Ymin This sets the screen. (0,0) will be at the center. :Degree Instead of this, it is possible to use a lot of ° calls. Or use Radians instead. :15 H:20 M:18 S This sets the length of the hands. The variables can be any real value, however they should be less than 25, as otherwise the background can be erased as the hands move. :Circle(0,0,30) :For(X,1,12) ::Text(28-int(cos(X*30)*25),46+int(sin(30*X)*25),X) :End This creates the background by drawing a circle (again, its radius can be changed) and the twelve numbers. The 28- and 46+ are necessitated by the Text( function because it does not use the graph's coordinate system. If you have a TI-84 Plus C Silver Edition, the previous section of code will not work. The numbers will be drawn small, clustered, and very off-centered. To fix: :Circle(0,0,30) :For(X,1,12) ::Text(75-int(cos(X*30)*70),130+int(sin(30*X)*70),X) :End Please use that code instead. ::If TIME(3)≠ ANG(3)/6:Line(0,0,sin( ANG(3))*S,cos( ANG(3))*S,0) :: ::If TIME(2)≠ ANG(2)/6:Then :::Line(0,0,sin( ANG(2))*M,cos( ANG(2))*M,0) :::Line(0,0,sin( ANG(1))*H,cos( ANG(1))*H,0) ::End This erases hands if the time has changed. Only the seconds hand if the minutes and hour are the same, If the minutes has changed, all hands are erased. :: TIME(1)*30+ TIME(2)/2 ANG(1) :: TIME(2)*6 ANG(2) :: TIME(3)*6 ANG(3) This sets the angle each hand has to be drawn at. The Minutes and Seconds hands are just drawn at their current value times 360/60. The Hours hand however includes the minutes value in determining where it is drawn. ::Line(0,0,sin( ANG(1))*H,cos( ANG(1))*H ::Line(0,0,sin( ANG(2))*M,cos( ANG(2))*M ::Line(0,0,sin( ANG(3))*S,cos( ANG(3))*S This draws the three hands. All three hands are drawn regardless of whether they were erased because part of one hand may be erased when the seconds hand erases; if minutes and seconds were both 30, for example, when the seconds hand erased, it would leave a hole in the minutes hand. Category:Programing Examples